package com.beike.controller;

import com.beike.entity.LessonDesign;
import com.beike.service.LessonDesignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/lesson-designs")
@CrossOrigin(origins = "http://localhost:5173")
public class LessonDesignController {

    @Autowired
    private LessonDesignService lessonDesignService;

    // 1. 生成教学设计
    @PostMapping("/generate")
    public ResponseEntity<LessonDesign> generateLessonDesign(
            @RequestParam String name,
            @RequestParam String subject,
            @RequestParam String grade,
            @RequestParam int duration) {
        LessonDesign design = lessonDesignService.generateDesign(name,subject, grade, duration);
        return ResponseEntity.ok(design);
    }

    // 2. 获取教学设计详情
    @GetMapping("/{id}")
    public ResponseEntity<LessonDesign> getLessonDesign(@PathVariable Long id) {
        LessonDesign design = lessonDesignService.getDesignById(id);
        return ResponseEntity.ok(design);
    }

    // 3. 保存教学设计
    @PostMapping
    public ResponseEntity<LessonDesign> saveLessonDesign(@RequestBody LessonDesign design) {
        LessonDesign savedDesign = lessonDesignService.saveDesign(design);
        return ResponseEntity.ok(savedDesign);
    }

    // 4. 获取所有教学设计
    @GetMapping
    public ResponseEntity<List<LessonDesign>> getAllLessonDesigns() {
        List<LessonDesign> designs = lessonDesignService.getAllDesigns();
        return ResponseEntity.ok(designs);
    }
} 